<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "UserSkill".
 */
class UserSkill extends ActiveRecord {

    // @name 熟练度
    const MasterCommonly = 0;
    const MasterSkilled = 1;
    const MasterPrefect = 2;
    public static $masterSelector = [
        self::MasterCommonly => ['title' => '一般', 'status' => 'orange'],
        self::MasterSkilled => ['title' => '熟练', 'status' => 'blue'],
        self::MasterPrefect => ['title' => '精通', 'status' => 'red'],
    ];

    // only define rules for those attributes that
    // will receive user inputs.
    public function rules()
    {
        return [
            [['user_id', 'name', 'master'], 'required'],
            [['user_id', 'master'], 'integer'],
            [['name'], 'string', 'max' => 32],
        ];
    }
    /**
     * @name 字段名称
     * @return array
     */
    public function attributeLabels()
    {
        return [
            'user_id' => '用户',
            'name' => '技能',
            'master' => '熟练度',
        ];
    }

    /**
     * @name 获取user信息
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }
}